<?php
class UserModel
{
	private $user_db;
	
	public function __construct()
	{
		$this->user_db = new UserDb();
	}
	
	public function addUserToDb($data)
	{
		return $this->user_db->insertRow($data);
	}
	
	public function getUserFromDbById($id)
	{
		$where = array(
			'id' => $id
		);
		$result = $this->user_db->selectRow($where);
		return $result;
	}
	
	public function getUserFromDbByName($name)
	{
		$where = array(
			'name' => $name
		);
		$result = $this->user_db->selectRow($where);
		return $result;
	}
	
	public function getUserFromGoogleFriendConnect($auth)
	{
		$user_google_friend_connect = new UserGoogleFriendConnect($auth);
		return $user_google_friend_connect->get();
	}
	
	public function setUserToDb($data)
	{
		$result = $this->getUserFromDbById($data['id']);
		if(empty($result))//todo why can't
		{
			$this->addUserToDb($data);
		}
		else
		{
			$this->updateUserToDb($data);
		}
		return true;
	}
	
	public function updateUserToDb($data)
	{
		$where = array(
			'id' => $data['id']
		);
		return $this->user_db->update($where, $data);
	}
}
?>